const Base = require('./base.js');
const fs = require('fs');
const picBaseUrl='http://127.0.0.1:8360';
module.exports = class extends Base {
  // async brandPicAction() {
  //   const brandFile = this.file('brand_pic');
  //   if (think.isEmpty(brandFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/brand/' + think.uuid(32) + '.jpg';
  //   const is = fs.createReadStream(brandFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'brand_pic',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }
  //
  // async brandNewPicAction() {
  //   const brandFile = this.file('brand_new_pic');
  //   if (think.isEmpty(brandFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/brand/' + think.uuid(32) + '.jpg';
  //
  //   const is = fs.createReadStream(brandFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'brand_new_pic',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }
  //
  // async categoryWapBannerPicAction() {
  //   const imageFile = this.file('wap_banner_pic');
  //   if (think.isEmpty(imageFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/category/' + think.uuid(32) + '.jpg';
  //
  //   const is = fs.createReadStream(imageFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'wap_banner_url',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }
  //
  // async topicThumbAction() {
  //   const imageFile = this.file('scene_pic_url');
  //   if (think.isEmpty(imageFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/topic/' + think.uuid(32) + '.jpg';
  //
  //   const is = fs.createReadStream(imageFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'scene_pic_url',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }
  //
  // async topicContentAction() {
  //   const imageFile = this.file('topic_content_pic');
  //   if (think.isEmpty(imageFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/topic/' + think.uuid(32) + '.jpg';
  //
  //   const is = fs.createReadStream(imageFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'topic_content_pic_url',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }
  //
  // /*liulizhi
  // 20181020
  // 商品详情页图片上传*/
  // async goodsDetailPicAction() {
  //   const imageFile = this.file('goods_detail_pic');
  //   if (think.isEmpty(imageFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/goods/' + think.uuid(32) + '.jpg';
  //
  //   const is = fs.createReadStream(imageFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'goods_detail_pic',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }
  //
  // /*liulizhi
  // 20181020
  // 商品轮播图片上传*/
  // async goodsGalleryPicAction() {
  //   const imageFile = this.file('goodsgallery_pic');
  //   if (think.isEmpty(imageFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/goodsgallery/' + think.uuid(32) + '.jpg';
  //
  //   const is = fs.createReadStream(imageFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'goodsgallery_pic',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }
  //
  // /*liulizhi
  // 20181023
  // 首页分类icon上传*/
  // async channelIconPicAction() {
  //   const imageFile = this.file('icon_pic');
  //   if (think.isEmpty(imageFile)) {
  //     return this.fail('保存失败');
  //   }
  //   const that = this;
  //   const filename = '/static/upload/iconpic/' + think.uuid(32) + '.jpg';
  //
  //   const is = fs.createReadStream(imageFile.path);
  //   const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
  //   is.pipe(os);
  //
  //   return that.success({
  //     name: 'channel_icon_pic',
  //     fileUrl: 'https://smallprogram.bjyangshi.com' + filename
  //   });
  // }

  /*liulizhi
  20181023
  首页分类icon上传*/
  async userPicAction() {
    const imageFile = this.file('user_pic');
    if (think.isEmpty(imageFile)) {
      return this.fail('保存失败');
    }
    const that = this;
    const filename = '/static/upload/userpic/' + think.uuid(32) + '.jpg';

    const is = fs.createReadStream(imageFile.path);
    const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
    is.pipe(os);

    return that.success({
      name: 'user_pic',
      fileUrl: picBaseUrl + filename
    });
  }


  /*liulizhi
  20181023
  广告位ad 图片上传*/
  async adPicAction() {
    const imageFile = this.file('ad_pic');
    if (think.isEmpty(imageFile)) {
      return this.fail('保存失败');
    }
    const that = this;
    const filename = '/static/upload/adpic/' + think.uuid(32) + '.jpg';

    const is = fs.createReadStream(imageFile.path);
    const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename);
    is.pipe(os);

    return that.success({
      name: 'ad_pic',
      fileUrl: picBaseUrl + filename
    });
  }
};
